﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace _14EFCore学习;

public class MyDbContext:DbContext
{
    public DbSet<Book> Books { get; set; }
    public DbSet<Person> Persons { get; set; }
    public DbSet<Cat> Cats { get; set; }
    private static ILoggerFactory _loggerFactory = LoggerFactory.Create(b => b.AddConsole());
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        string connstr = "Server=Localhost;Database=efCorePractice;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=true;";
        optionsBuilder.UseSqlServer(connstr);
        optionsBuilder.UseLoggerFactory(_loggerFactory);
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
    }
}